package com.school.controller;


import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.school.service.impl.HljtDeviceServiceImpl;
import com.school.util.JsonUtil;
import com.alibaba.fastjson.JSONObject;

@Controller
public class HljtEditionController {

	
	@Autowired
	private HljtDeviceServiceImpl hljtDeviceServiceImpl;
	
	/**
	 * 设备跟新接口
	 * @param mac mac地址
	 * @param edition  版本号
	 * @return
	 * @throws UnknownHostException 
	 * @throws Exception 
	 */
	@RequestMapping(value="/update")
	@ResponseBody
	public JSONObject selectSchoolImagesByType(String versionCode,String versionName ,String mac , JsonUtil jsonUtil){
		 if(null !=versionCode  && null!=mac) {
			try {
				Map<String, Object> device = hljtDeviceServiceImpl.findDeviceEX(versionCode,versionName,mac);
				/*Map<String, Object> device = hljtDeviceServiceImpl.findDeviceEX(versionCode,versionName,mac);
				ret.put("isUpdate", device.get("type"));
				ret.put("updateUrl", device.get("data"));
				ret.put("msg", device.get("msg"));*/
				jsonUtil.setSucceed(device,"请求成功");
			} catch (Exception e) {
				e.printStackTrace();
			}
		 }else {
			 jsonUtil.setFailMsg("参数错误");
		 }
		 return jsonUtil.toJSONString();
}
	
	
	/**
	 * 获取本电脑ip
	 * @return
	 * @throws UnknownHostException
	 */
	public static String getIp() throws UnknownHostException {
		InetAddress addr = InetAddress.getLocalHost();  
        String ip=addr.getHostAddress().toString();
		return ip;
	}
	
}
